home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2001 May / may_2001.iso / intercd / root / Multimedia / ^DivX_Article / virtualdub / VirtualDub-source-1_4d / prefs.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2001-03-20  |  14.5 KB  |  454 lines

  1. //    VirtualDub - Video processing and capture application
  2. //    Copyright (C) 1998-2001 Avery Lee
  3. //
  4. //    This program is free software; you can redistribute it and/or modify
  5. //    it under the terms of the GNU General Public License as published by
  6. //    the Free Software Foundation; either version 2 of the License, or
  7. //    (at your option) any later version.
  8. //
  9. //    This program is distributed in the hope that it will be useful,
  10. //    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. //    GNU General Public License for more details.
  13. //
  14. //    You should have received a copy of the GNU General Public License
  15. //    along with this program; if not, write to the Free Software
  16. //    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  
  18. #define f_PREFS_CPP
  19.  
  20. #include <windows.h>
  21. #include <commctrl.h>
  22.  
  23. #include "resource.h"
  24. #include "helpfile.h"
  25.  
  26. #include "gui.h"
  27. #include "oshelper.h"
  28. #include "dub.h"
  29. #include "dubstatus.h"
  30. #include "prefs.h"
  31.  
  32. extern HINSTANCE g_hInst;
  33.  
  34. Preferences g_prefs={
  35.     { 0, PreferencesMain::DEPTH_FASTEST, 0, TRUE, 0 },
  36.     { 50*16, 4*16 },
  37. };
  38.  
  39. static char g_szMainPrefs[]="Main prefs";
  40.  
  41. ////////////////////////////////////////////////////////////////
  42.  
  43. static DWORD dwPrefsHelpLookup[]={
  44.     IDC_OUTPUT_DEPTH,            IDH_PREFS_MAIN_OUTPUTCOLORDEPTH,
  45.     IDC_PREVIEW_PRIORITY,        IDH_PREFS_MAIN_PROCESSPRIORITY,
  46.     IDC_DUB_PRIORITY,            IDH_PREFS_MAIN_PROCESSPRIORITY,
  47.     IDC_TACK_EXTENSION,            IDH_PREFS_MAIN_ADDEXTENSION,        
  48.     IDC_ENABLE_16DITHERING,        IDH_PREFS_DISPLAY_16BITDITHER,
  49.     IDC_INTERFRAME_SLIDER,        IDH_PREFS_SCENE_INTERFRAME,
  50.     IDC_INTRAFRAME_SLIDER,        IDH_PREFS_SCENE_INTRAFRAME,
  51.     IDC_PERFOPT_DEFAULT,        IDH_PREFS_CPU_OPTIMIZATIONS,
  52.     IDC_PERFOPT_FORCE,            IDH_PREFS_CPU_OPTIMIZATIONS,
  53.     IDC_PERFOPT_FPU,            IDH_PREFS_CPU_OPTIMIZATIONS,
  54.     IDC_PERFOPT_MMX,            IDH_PREFS_CPU_OPTIMIZATIONS,
  55.     IDC_RESTRICT_AVI_1GB,        IDH_PREFS_AVI_RESTRICT_1GB,
  56.     IDC_AUTOCORRECT_L3,            IDH_PREFS_AVI_AUTOCORRECT_L3,
  57.     0
  58. };
  59.  
  60. typedef struct PrefsDlgData {
  61.     Preferences prefs;
  62.  
  63.     HWND hwndDisplay;
  64.     RECT rcTab;
  65. } PrefsDlgData;
  66.  
  67. static void PreferencesChildPosition(HWND hWnd, PrefsDlgData *pdd) {
  68.     SetWindowPos(hWnd, HWND_TOP, pdd->rcTab.left, pdd->rcTab.top, 0, 0, SWP_NOSIZE);
  69. }
  70.  
  71. static BOOL APIENTRY PreferencesMainDlgProc( HWND hDlg, UINT message, UINT wParam, LONG lParam) {
  72.     static char *szDepths[]={
  73.         "Fastest (16-bit)",
  74.         "Use output setting",
  75.         "Match display depth",
  76.         "16-bit (HiColor)",
  77.         "24-bit (TrueColor)",
  78.     };
  79.  
  80.     PrefsDlgData *pdd = (PrefsDlgData *)GetWindowLong(hDlg, DWL_USER);
  81.     HWND hwndItem;
  82.     int i;
  83.  
  84.     switch(message) {
  85.         case WM_INITDIALOG:
  86.             PreferencesChildPosition(hDlg, (PrefsDlgData *)lParam);
  87.             SetWindowLong(hDlg, DWL_USER, lParam);
  88.             pdd = (PrefsDlgData *)lParam;
  89.  
  90.             //////////////
  91.  
  92.             hwndItem = GetDlgItem(hDlg, IDC_OUTPUT_DEPTH);
  93.             for(i=0; i<5; i++)
  94.                 SendMessage(hwndItem, CB_ADDSTRING, 0, (LPARAM)szDepths[i]);
  95.  
  96.             SendMessage(hwndItem, CB_SETCURSEL, pdd->prefs.main.iPreviewDepth, 0);
  97.  
  98.  
  99.             hwndItem = GetDlgItem(hDlg, IDC_PREVIEW_PRIORITY);
  100.             SendMessage(hwndItem, CB_ADDSTRING, 0, (LPARAM)"Default");
  101.             for(i=0; i<8; i++)
  102.                 SendMessage(hwndItem, CB_ADDSTRING, 0, (LPARAM)g_szDubPriorities[i]);
  103.  
  104.             SendMessage(hwndItem, CB_SETCURSEL, pdd->prefs.main.iPreviewPriority, 0);
  105.  
  106.             hwndItem = GetDlgItem(hDlg, IDC_DUB_PRIORITY);
  107.             SendMessage(hwndItem, CB_ADDSTRING, 0, (LPARAM)"Default");
  108.             for(i=0; i<8; i++)
  109.                 SendMessage(hwndItem, CB_ADDSTRING, 0, (LPARAM)g_szDubPriorities[i]);
  110.  
  111.             SendMessage(hwndItem, CB_SETCURSEL, pdd->prefs.main.iDubPriority, 0);
  112.  
  113.             //////////////
  114.  
  115.             CheckDlgButton(hDlg, IDC_TACK_EXTENSION, pdd->prefs.main.fAttachExtension);
  116.             return TRUE;
  117.  
  118.         case WM_DESTROY:
  119.             pdd->prefs.main.iPreviewDepth = (char)SendDlgItemMessage(hDlg, IDC_OUTPUT_DEPTH, CB_GETCURSEL, 0, 0);
  120.             pdd->prefs.main.iPreviewPriority = (char)SendDlgItemMessage(hDlg, IDC_PREVIEW_PRIORITY, CB_GETCURSEL, 0, 0);
  121.             pdd->prefs.main.iDubPriority = (char)SendDlgItemMessage(hDlg, IDC_DUB_PRIORITY, CB_GETCURSEL, 0, 0);
  122.             pdd->prefs.main.fAttachExtension = IsDlgButtonChecked(hDlg, IDC_TACK_EXTENSION);
  123.             return TRUE;
  124.     }
  125.  
  126.     return FALSE;
  127. }
  128.  
  129. static BOOL APIENTRY PreferencesDisplayDlgProc( HWND hDlg, UINT message, UINT wParam, LONG lParam) {
  130.     PrefsDlgData *pdd = (PrefsDlgData *)GetWindowLong(hDlg, DWL_USER);
  131.  
  132.     switch(message) {
  133.         case WM_INITDIALOG:
  134.             PreferencesChildPosition(hDlg, (PrefsDlgData *)lParam);
  135.             SetWindowLong(hDlg, DWL_USER, lParam);
  136.             pdd = (PrefsDlgData *)lParam;
  137.  
  138.             //////////////
  139.  
  140.             CheckDlgButton(hDlg, IDC_ENABLE_16DITHERING, !!(pdd->prefs.fDisplay & Preferences::DISPF_DITHER16));
  141.  
  142.             return TRUE;
  143.  
  144.         case WM_DESTROY:
  145.             pdd->prefs.fDisplay = IsDlgButtonChecked(hDlg, IDC_ENABLE_16DITHERING) ? Preferences::DISPF_DITHER16 : 0;
  146.             return TRUE;
  147.     }
  148.  
  149.     return FALSE;
  150. }
  151.  
  152. static BOOL APIENTRY PreferencesSceneDlgProc( HWND hDlg, UINT message, UINT wParam, LONG lParam) {
  153.     PrefsDlgData *pdd = (PrefsDlgData *)GetWindowLong(hDlg, DWL_USER);
  154.     HWND hwndItem;
  155.     long pos;
  156.  
  157.     switch(message) {
  158.         case WM_INITDIALOG:
  159.             PreferencesChildPosition(hDlg, (PrefsDlgData *)lParam);
  160.             SetWindowLong(hDlg, DWL_USER, lParam);
  161.             pdd = (PrefsDlgData *)lParam;
  162.  
  163.             //////////////
  164.  
  165.             hwndItem = GetDlgItem(hDlg, IDC_INTERFRAME_SLIDER);
  166.             SendMessage(hwndItem, TBM_SETRANGE, FALSE, MAKELONG(0,255));
  167.             SendMessage(hwndItem, TBM_SETPOS, TRUE,
  168.                     pdd->prefs.scene.iCutThreshold
  169.                         ? 256 - ((pdd->prefs.scene.iCutThreshold+8)>>4)
  170.                         : 0
  171.                     );
  172.             SendMessage(hDlg, WM_HSCROLL, 0, (LPARAM)hwndItem);
  173.  
  174.             hwndItem = GetDlgItem(hDlg, IDC_INTRAFRAME_SLIDER);
  175.             SendMessage(hwndItem, TBM_SETRANGE, FALSE, MAKELONG(0,256));
  176.             SendMessage(hwndItem, TBM_SETPOS, TRUE, pdd->prefs.scene.iFadeThreshold);
  177.             SendMessage(hDlg, WM_HSCROLL, 0, (LPARAM)hwndItem);
  178.  
  179.             return TRUE;
  180.  
  181.         case WM_HSCROLL:
  182.             pos = SendMessage((HWND)lParam, TBM_GETPOS, 0, 0);
  183.             switch(GetWindowLong((HWND)lParam, GWL_ID)) {
  184.             case IDC_INTERFRAME_SLIDER:
  185.                 if (!pos)
  186.                     SetDlgItemText(hDlg, IDC_INTERFRAME_VALUE, "Off");
  187.                 else
  188.                     SetDlgItemInt(hDlg, IDC_INTERFRAME_VALUE, pos, FALSE);
  189.                 return TRUE;
  190.             case IDC_INTRAFRAME_SLIDER:
  191.                 if (!pos)
  192.                     SetDlgItemText(hDlg, IDC_INTRAFRAME_VALUE, "Off");
  193.                 else
  194.                     SetDlgItemInt(hDlg, IDC_INTRAFRAME_VALUE, pos, FALSE);
  195.  
  196.                 return TRUE;
  197.             }
  198.             break;
  199.  
  200.         case WM_DESTROY:
  201.             {
  202.                 int x = SendDlgItemMessage(hDlg, IDC_INTERFRAME_SLIDER, TBM_GETPOS, 0, 0);
  203.  
  204.                 pdd->prefs.scene.iCutThreshold = x?(256-x)<<4:0;
  205.                 pdd->prefs.scene.iFadeThreshold = SendDlgItemMessage(hDlg, IDC_INTRAFRAME_SLIDER, TBM_GETPOS, 0, 0);
  206.             }
  207.             return TRUE;
  208.     }
  209.  
  210.     return FALSE;
  211. }
  212.  
  213. static BOOL APIENTRY PreferencesCPUDlgProc(HWND hDlg, UINT message, UINT wParam, LONG lParam) {
  214.     PrefsDlgData *pdd = (PrefsDlgData *)GetWindowLong(hDlg, DWL_USER);
  215.     BOOL fTemp;
  216.  
  217.     switch(message) {
  218.         case WM_INITDIALOG:
  219.             PreferencesChildPosition(hDlg, (PrefsDlgData *)lParam);
  220.             SetWindowLong(hDlg, DWL_USER, lParam);
  221.             pdd = (PrefsDlgData *)lParam;
  222.  
  223.             //////////////
  224.  
  225.             CheckDlgButton(hDlg, IDC_PERFOPT_FPU, !!(pdd->prefs.main.fOptimizations & PreferencesMain::OPTF_FPU));
  226.             CheckDlgButton(hDlg, IDC_PERFOPT_MMX, !!(pdd->prefs.main.fOptimizations & PreferencesMain::OPTF_MMX));
  227.             CheckDlgButton(hDlg, IDC_PERFOPT_SSE, !!(pdd->prefs.main.fOptimizations & PreferencesMain::OPTF_SSE));
  228.             CheckDlgButton(hDlg, IDC_PERFOPT_SSE2, !!(pdd->prefs.main.fOptimizations & PreferencesMain::OPTF_SSE2));
  229.             CheckDlgButton(hDlg, IDC_PERFOPT_SSEPARTIAL, !!(pdd->prefs.main.fOptimizations & PreferencesMain::OPTF_INTEGER_SSE));
  230.             CheckDlgButton(hDlg, IDC_PERFOPT_3DNOW, !!(pdd->prefs.main.fOptimizations & PreferencesMain::OPTF_3DNOW));
  231.             CheckDlgButton(hDlg, IDC_PERFOPT_3DNOW2, !!(pdd->prefs.main.fOptimizations & PreferencesMain::OPTF_3DNOW_EXT));
  232.  
  233.             if (pdd->prefs.main.fOptimizations & PreferencesMain::OPTF_FORCE) {
  234.                 CheckDlgButton(hDlg, IDC_PERFOPT_FORCE, TRUE);
  235.             } else {
  236.                 CheckDlgButton(hDlg, IDC_PERFOPT_DEFAULT, TRUE);
  237.                 EnableWindow(GetDlgItem(hDlg, IDC_PERFOPT_FPU), FALSE);
  238.                 EnableWindow(GetDlgItem(hDlg, IDC_PERFOPT_MMX), FALSE);
  239.                 EnableWindow(GetDlgItem(hDlg, IDC_PERFOPT_SSE), FALSE);
  240.                 EnableWindow(GetDlgItem(hDlg, IDC_PERFOPT_SSE2), FALSE);
  241.                 EnableWindow(GetDlgItem(hDlg, IDC_PERFOPT_SSEPARTIAL), FALSE);
  242.                 EnableWindow(GetDlgItem(hDlg, IDC_PERFOPT_3DNOW), FALSE);
  243.                 EnableWindow(GetDlgItem(hDlg, IDC_PERFOPT_3DNOW2), FALSE);
  244.             }
  245.  
  246.             return TRUE;
  247.  
  248.         case WM_COMMAND:
  249.             switch(LOWORD(wParam)) {
  250.             case IDC_PERFOPT_DEFAULT:
  251.             case IDC_PERFOPT_FORCE:
  252.                 fTemp = !!(SendMessage(GetDlgItem(hDlg, IDC_PERFOPT_FORCE), BM_GETSTATE, 0, 0)&3);
  253.                 EnableWindow(GetDlgItem(hDlg, IDC_PERFOPT_FPU), fTemp);
  254.                 EnableWindow(GetDlgItem(hDlg, IDC_PERFOPT_MMX), fTemp);
  255.                 EnableWindow(GetDlgItem(hDlg, IDC_PERFOPT_SSE), fTemp);
  256.                 EnableWindow(GetDlgItem(hDlg, IDC_PERFOPT_SSE2), fTemp);
  257.                 EnableWindow(GetDlgItem(hDlg, IDC_PERFOPT_SSEPARTIAL), fTemp);
  258.                 EnableWindow(GetDlgItem(hDlg, IDC_PERFOPT_3DNOW), fTemp);
  259.                 EnableWindow(GetDlgItem(hDlg, IDC_PERFOPT_3DNOW2), fTemp);
  260.             }
  261.             return TRUE;
  262.  
  263.         case WM_DESTROY:
  264.             pdd->prefs.main.fOptimizations    = (IsDlgButtonChecked(hDlg, IDC_PERFOPT_FORCE) ? PreferencesMain::OPTF_FORCE : 0)
  265.                                             | (IsDlgButtonChecked(hDlg, IDC_PERFOPT_FPU) ? PreferencesMain::OPTF_FPU : 0)
  266.                                             | (IsDlgButtonChecked(hDlg, IDC_PERFOPT_MMX) ? PreferencesMain::OPTF_MMX : 0)
  267.                                             | (IsDlgButtonChecked(hDlg, IDC_PERFOPT_3DNOW) ? PreferencesMain::OPTF_3DNOW : 0)
  268.                                             | (IsDlgButtonChecked(hDlg, IDC_PERFOPT_3DNOW2) ? PreferencesMain::OPTF_3DNOW_EXT : 0)
  269.                                             | (IsDlgButtonChecked(hDlg, IDC_PERFOPT_SSEPARTIAL) ? PreferencesMain::OPTF_INTEGER_SSE : 0)
  270.                                             | (IsDlgButtonChecked(hDlg, IDC_PERFOPT_SSE) ? PreferencesMain::OPTF_SSE : 0)
  271.                                             | (IsDlgButtonChecked(hDlg, IDC_PERFOPT_SSE2) ? PreferencesMain::OPTF_SSE2 : 0);
  272.             return TRUE;
  273.     }
  274.  
  275.     return FALSE;
  276. }
  277.  
  278. static BOOL APIENTRY PreferencesAVIDlgProc(HWND hdlg, UINT message, UINT wParam, LONG lParam) {
  279.     PrefsDlgData *pdd = (PrefsDlgData *)GetWindowLong(hdlg, DWL_USER);
  280.  
  281.     switch(message) {
  282.         case WM_INITDIALOG:
  283.             PreferencesChildPosition(hdlg, (PrefsDlgData *)lParam);
  284.             SetWindowLong(hdlg, DWL_USER, lParam);
  285.             pdd = (PrefsDlgData *)lParam;
  286.  
  287.             //////////////
  288.  
  289.             CheckDlgButton(hdlg, IDC_RESTRICT_AVI_1GB, !!pdd->prefs.fAVIRestrict1Gb);
  290.             CheckDlgButton(hdlg, IDC_AUTOCORRECT_L3, !!pdd->prefs.fNoCorrectLayer3);
  291.             return TRUE;
  292.  
  293.         case WM_DESTROY:
  294.             pdd->prefs.fAVIRestrict1Gb = IsDlgButtonChecked(hdlg, IDC_RESTRICT_AVI_1GB);
  295.             pdd->prefs.fNoCorrectLayer3 = IsDlgButtonChecked(hdlg, IDC_AUTOCORRECT_L3);
  296.             return TRUE;
  297.     }
  298.  
  299.     return FALSE;
  300. }
  301.  
  302. ////////////////////////////////////////////////////////////////
  303.  
  304. static struct prefsTabs {
  305.     LPTSTR    rsrc;
  306.     char    *name;
  307.     DLGPROC    dProc;
  308. } tabs[]={
  309.     {    MAKEINTRESOURCE(IDD_PREFS_MAIN),    "Main",        PreferencesMainDlgProc    },
  310.     {    MAKEINTRESOURCE(IDD_PREFS_DISPLAY),    "Display",    PreferencesDisplayDlgProc },
  311.     {    MAKEINTRESOURCE(IDD_PREFS_SCENE),    "Scene",    PreferencesSceneDlgProc    },
  312.     {    MAKEINTRESOURCE(IDD_PREFS_CPU),        "CPU",        PreferencesCPUDlgProc    },
  313.     {    MAKEINTRESOURCE(IDD_PREFS_AVI),        "AVI",        PreferencesAVIDlgProc    },
  314. };
  315.  
  316. BOOL APIENTRY PreferencesDlgProc( HWND hDlg, UINT message, UINT wParam, LONG lParam) {
  317.  
  318.     PrefsDlgData *pdd = (PrefsDlgData *)GetWindowLong(hDlg, DWL_USER);
  319.  
  320.     //////////
  321.  
  322.     switch(message) {
  323.         case WM_INITDIALOG:
  324.             {
  325.                 RECT r, r2;
  326.                 LONG du = GetDialogBaseUnits();
  327.                 LONG duX = LOWORD(du);
  328.                 LONG duY = HIWORD(du);
  329.                 HWND hWndTab = GetDlgItem(hDlg, IDC_TAB);
  330.                 LONG xDelta, yDelta;
  331.                 POINT p;
  332.                 int i;
  333.  
  334.                 if (!(pdd = new PrefsDlgData)) return FALSE;
  335.                 memset(pdd, 0, sizeof pdd);
  336.                 SetWindowLong(hDlg, DWL_USER, (LPARAM)pdd);
  337.  
  338.                 pdd->prefs = g_prefs;
  339.  
  340.                 for(i=0; i<(sizeof tabs/sizeof tabs[0]); i++) {
  341.                     TC_ITEM ti;
  342.  
  343.                     ti.mask        = TCIF_TEXT;
  344.                     ti.pszText    = tabs[i].name;
  345.  
  346.                     TabCtrl_InsertItem(hWndTab, i, &ti);
  347.                 }
  348.  
  349.                 r.left = r.top = 0;
  350.                 r.right = 250;
  351.                 r.bottom = 150;
  352.                 MapDialogRect(hDlg, &r);
  353.  
  354.                 GetWindowRect(hWndTab, &r2);
  355.                 p.x = r2.left;
  356.                 p.y = r2.top;
  357.                 ScreenToClient(hDlg, &p);
  358.                 pdd->rcTab = r;
  359.  
  360.                 TabCtrl_AdjustRect(hWndTab, TRUE, &r);
  361.                 OffsetRect(&pdd->rcTab, p.x-r.left, p.y-r.top);
  362.  
  363.                 xDelta = (r.right-r.left) - (r2.right-r2.left);
  364.                 yDelta = (r.bottom-r.top) - (r2.bottom-r2.top);
  365.  
  366.                 SetWindowPos(hWndTab, NULL, 0, 0, r.right-r.left, r.bottom-r.top, SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
  367.  
  368.                 guiOffsetDlgItem(hDlg, IDC_SAVE, xDelta, yDelta);
  369.                 guiOffsetDlgItem(hDlg, IDOK, xDelta, yDelta);
  370.                 guiOffsetDlgItem(hDlg, IDCANCEL, xDelta, yDelta);
  371.  
  372.                 GetWindowRect(hDlg, &r);
  373.                 SetWindowPos(hDlg, NULL, 0, 0, r.right-r.left + xDelta, r.bottom-r.top + yDelta, SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
  374.  
  375.                 pdd->hwndDisplay = CreateDialogParam(g_hInst, tabs[0].rsrc, hDlg, tabs[0].dProc, (LPARAM)pdd);
  376.             }
  377.             return TRUE;
  378.  
  379.         case WM_DESTROY:
  380.             if (pdd) {
  381.                 delete pdd;
  382.                 SetWindowLong(hDlg, DWL_USER, 0);
  383.             }
  384.             return TRUE;
  385.  
  386.         case WM_NOTIFY: {
  387.             NMHDR *nm = (LPNMHDR)lParam;
  388.  
  389.             switch(nm->code) {
  390.             case TCN_SELCHANGE:
  391.                 {
  392.                     int iTab = TabCtrl_GetCurSel(nm->hwndFrom);
  393.  
  394.                     if (iTab>=0) {
  395.                         if (pdd->hwndDisplay) DestroyWindow(pdd->hwndDisplay);
  396.                         pdd->hwndDisplay = CreateDialogParam(g_hInst, tabs[iTab].rsrc, hDlg, tabs[iTab].dProc, (LPARAM)pdd);
  397.                     }
  398.                 }
  399.                 return TRUE;
  400.             }
  401.             }break;
  402.  
  403.         case WM_COMMAND:
  404.             switch(LOWORD(wParam)) {
  405.             case IDC_SAVE:
  406.             case IDOK:
  407.                 if (pdd->hwndDisplay) {
  408.                     DestroyWindow(pdd->hwndDisplay);
  409.                     pdd->hwndDisplay = NULL;
  410.                 }
  411.                 g_prefs = pdd->prefs;
  412.  
  413.                 if (LOWORD(wParam) == IDC_SAVE) {
  414.                     SetConfigBinary("", g_szMainPrefs, (char *)&g_prefs, sizeof g_prefs);
  415.                 }
  416.  
  417.                 EndDialog(hDlg, TRUE);
  418.                 return TRUE;
  419.             case IDCANCEL:
  420.                 if (pdd->hwndDisplay) {
  421.                     DestroyWindow(pdd->hwndDisplay);
  422.                     pdd->hwndDisplay = NULL;
  423.                 }
  424.                 EndDialog(hDlg, FALSE);
  425.                 return TRUE;
  426.             }
  427.             break;
  428.  
  429.         case WM_HELP:
  430.             {
  431.                 HELPINFO *lphi = (HELPINFO *)lParam;
  432.  
  433.                 if (lphi->iContextType == HELPINFO_WINDOW)
  434.                     HelpPopupByID(hDlg, lphi->iCtrlId, dwPrefsHelpLookup);
  435.             }
  436.             return TRUE;
  437.     }
  438.  
  439.     return FALSE;
  440. }
  441.  
  442. void LoadPreferences() {
  443.     DWORD dwSize;
  444.     Preferences prefs_t;
  445.  
  446.     dwSize = QueryConfigBinary("", g_szMainPrefs, (char *)&prefs_t, sizeof prefs_t);
  447.  
  448.     if (dwSize) {
  449.         if (dwSize > sizeof g_prefs) dwSize = sizeof g_prefs;
  450.  
  451.         memcpy(&g_prefs, &prefs_t, dwSize);
  452.     }
  453. }
  454.